package com.scf.enterprise.controller;

import com.scf.enterprise.entity.EccontactInfor;
import com.scf.enterprise.entity.EnterpriseIfmtion;
import com.scf.enterprise.entity.LegalPerson;
import com.scf.enterprise.entity.PageBean;
import com.scf.enterprise.service.serviceImpl.EnterpriseServiceImpl;
import com.scf.uitl.ResponseResult;
import com.scf.uitl.ResultStatus;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/enp")
public class EnterpriseController {

    @Resource
    private EnterpriseServiceImpl enterpriseService;

    @GetMapping("/allenp")
    public ResponseResult<PageBean<EnterpriseIfmtion>> getAll(String epname,int epstate, int pageIndex, int pageSize){

        EnterpriseIfmtion epinfo = new EnterpriseIfmtion();
        if (epname != null && epname != ""){
            epinfo.setEpname(epname);
        }
        if (epstate != 0){
            epinfo.setEpstate(epstate);
        }
        List<EnterpriseIfmtion> enterpriseIfmtions = enterpriseService.selectAll(epinfo,pageIndex,pageSize);
        PageBean<EnterpriseIfmtion> pageBean = new PageBean<>();
        pageBean.setPageBeanList(enterpriseIfmtions);
        pageBean.setPageIndex(pageIndex);
        pageBean.setPageSize(pageSize);
        int totalRecord = enterpriseService.selectEpCount(epinfo);
        pageBean.setTotalRecord(totalRecord);

        return new ResponseResult(200, ResultStatus.SUCCESS, "所有企业信息", pageBean);
    }



    @GetMapping("/epbyid/{epid}")
    public ResponseResult<EnterpriseIfmtion> getEpByid(@PathVariable("epid") int epid){

        EnterpriseIfmtion enterpriseIfmtion = enterpriseService.selectepByid(epid);

        return new ResponseResult<>(200, ResultStatus.SUCCESS,"ById企业信息",enterpriseIfmtion);
    }


    @PutMapping("/updateEpstate/{epid}/{epstate}")
    public ResponseResult<EnterpriseIfmtion> updateEpState(@PathVariable("epid") int epid,@PathVariable("epstate")int epstate){
        enterpriseService.updateepStateByid(epid, epstate);
        return new ResponseResult<>(200, ResultStatus.SUCCESS,"当前修改黑名单状态",null);
    }

    @PutMapping("/updateEp")
    public ResponseResult<EnterpriseIfmtion> updateEp(@RequestBody EnterpriseIfmtion epinfo){

        enterpriseService.updateEp(epinfo);
        return new ResponseResult<>(200, ResultStatus.SUCCESS,"修改企业基本信息",null);
    }


    @PutMapping("/updateLp")
    public ResponseResult<EnterpriseIfmtion> updateEp(@RequestBody LegalPerson leper){
        enterpriseService.updateLp(leper);
        return new ResponseResult<>(200, ResultStatus.SUCCESS,"修改法人基本信息",null);
    }


    @PutMapping("/updateEcc")
    public ResponseResult<EnterpriseIfmtion> updateEp(@RequestBody EccontactInfor ecc){
        enterpriseService.updateEcc(ecc);
        return new ResponseResult<>(200, ResultStatus.SUCCESS,"修改联系人基本信息",null);
    }

    @PostMapping("/insertEp")
    public ResponseResult<EnterpriseIfmtion> insertEpdata(@RequestBody EnterpriseIfmtion epinfo){

        enterpriseService.insertLpData(epinfo);

        enterpriseService.insertEccData(epinfo);

        enterpriseService.insertEpData(epinfo);


        return new ResponseResult<>(200, ResultStatus.SUCCESS,"添加企业信息",null);
    }

}
